var deleteID = '';
var vm = new Vue({
    el: "#app",
    data:
        {
            pageModel: '',
            messages: '',
            timer: null
        },
    // 方法存放区
    methods: {
        send() {
            axios({
                method: 'POST',
                url: '/draftBox/get'
            }).then(function (res) {
                vm.pageModel = res.data;
                vm.messages = res.data.data;
            }).catch(function (reason) {
                console.log(reason);
            })
        },
        // 删除
        delectCheck(informationId) {
            deleteID = informationId
            $(".tip").fadeIn(200);
        },
        // 修改留言
        updateMessage(informationId) {
            window.location.href = "updateDraftBox.html?no=" + informationId
        },
        // 查询留言
        getOne(informationId) {
            window.location.href = "DraftBoxView.html?no=" + informationId
        },
        // 删除确认
        delectCheck2() {
            axios.post('/draftBox/delete/' + deleteID)
                .then(function (response) {
                    alert(response.data)
                    vm.send()
                })
                .catch(function (error) {
                    alert(response.data)
                });
        }, //点击分页
        clickPageModel(num) {
            var s1 = $("input[name='messageIntro']").val();
            var s2 = $("input[name='sender']").val();
            var s3 = $("input[name='accept']").val();
            console.log(num)
            axios({
                method: 'POST',
                url: '/draftBox/get',
                params: {
                    "title": s1,
                    "sender":s2,
                    "receiver":s3,
                    "pageNum": num
                }
            }).then(function (res) {
                vm.pageModel = res.data;
                vm.messages = res.data.data;
            }).catch(function (reason) {
                console.log(reason);
            })
        },
        getByCondition() {
            var s1 = $("input[name='messageIntro']").val();
            var s2 = $("input[name='sender']").val();
            var s3 = $("input[name='accept']").val();
            if (s1 == '' && s2 == '' && s3 == '') {
                alert("请选择条件");
            } else {
                axios({
                    method: 'POST',
                    url: '/draftBox/get',
                    params: {
                        "title": s1,
                        "sender": s2,
                        "receiver": s3,
                    }
                }).then(function (res) {
                    vm.pageModel = res.data;
                    vm.messages = res.data.data;
                    if (vm.pageModel.totalRows == 0) {
                        alert("没有相关信息")
                    }
                }).catch(function (reason) {
                    console.log(reason);
                })
            }
        },
    },
    //页面加载完自动执行
    mounted() {
        this.send();
    }
});


